Skip to content

Commit

Permalink
Modify index even when dealing with terminal symbols to fix bugs of i…
Browse files Browse the repository at this point in the history
…ndex
  • Loading branch information
Matts966 committed Feb 10, 2020
1 parent e9ff9a5 commit 3d0f190
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/typescript/while-lang/WhileLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export class DefaultVisitor implements Visitor {
process.stdout.write(" ")
process.stdout.write("assign")
process.stdout.write(" ")
host.arg1.accept(this)
host.arg2.accept(this)
}
visitSkip(host : Skip) {
process.stdout.write("skip")
Expand Down
4 changes: 1 addition & 3 deletions src/GenerateTypeScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,15 @@ tellASTDefinitions = do
forM_ (syntaxRules syntax nt) $ \rule -> do
let className = pascalCase (ruleName rule)
tellsLn $ "\tvisit" ++ className ++ "(host : " ++ className ++ ") {"


_ <- (`execStateT` 0) $ forMWithSep_ (tellsLn $ "\t\tprocess.stdout.write(\" \")") (zip [1 ..] (ruleRhs rule)) $ \(i, sym) -> case sym of
NonTerminalSymbol nt -> do
j <- modify (\c -> c + 1) >> get
tellsLn $ "\t\thost.arg" ++ show j ++ ".accept(this)"

TerminalSymbol t -> do
if 0 < (length $ terminalParams t)
then
forMWithSep_ (tellsLn $ "\t\tprocess.stdout.write(\" \")") (zip [1 ..] (terminalParams t)) $ \(k, param) -> do
modify (\c -> c + 1)
tellsLn $ "\t\tprocess.stdout.write(\"\"+host.arg" ++ show k ++ ")"
else
tellsLn $ "\t\tprocess.stdout.write(\"" ++ (terminalName t) ++ "\")"
Expand Down

0 comments on commit 3d0f190

Please sign in to comment.