mgriebling / Coco

Swift version of the Coco/R Compiler Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to generate Parser.swift and Scanner.swift from my own Grammar

chrisbansart opened this issue · comments

Dear all,
I'm a new user of Coco, and would like to generate my parser and scanner in swift. Unfortunately it works with the Coco.jar witch command : java -jar Coco.jar MyGrammar.ATG which returns "parser + scanner generated" and creates these 2 files.
With Coco/R Swift project, through XCode or by terminal, I had not be able to produce these two files. Any ideas ?
Tx
Chris

Thank you Mike.
I did that, afterwards the program told me that my grammar is ok, but it doesn't produce the parser.swift and scanner.swift as I could expect.
I use this:
mb-cb$ ./Coco Grammar.ATG
Coco/R (April 7, 2016)
checking
0 errors detected
=> No parser.swift and scanner.swift produced
I also try all options associated with the ./Coco it changes nothing.

At the opposite, when I use the same command with the Java version:
$java -jar Coco.jar Grammar.ATG
Coco/R (Apr 19, 2011)
checking
parser + scanner generated
0 errors detected

=> The program produced the parser.java and the scanner.java according to my Grammar.

Yes, the Scanner.frame and Parser.frame are in the same directory than my Grammar.ATG
Tx
Christophe

Hi, I restart from the beginning Coco works great now, and generate 2 swift files.
My grammar has not errors but some rule that cannot be reached, it may the reason why the files are not generated. Please find in attachment (I've changed the extension of grammar .ATG by .txt due to the filter of github)
Wims.txt

Looked at your grammar and the errors about not being able to reach productions such as VarAlloc, RandInt, etc are occurring because your syntax never uses those productions. Either comment them out or put them in your top-level production:

Wims = TitleDef LangageDef AuthorDef EmailDef ComputeanswerDef PrecisionDef [Range] {Integer} StatementDef AnswerDef

    // remove errors by adding unreachable productions
    VarAlloc RandInt Rational Real Complex RangeDef HintDef HelpDef ConditionDef
    FeedbackDef SolutionDef Text Matrix Function
.

I was then able to generate the output files:

iMac:Coco mikeg$ coco Wims.atg
Coco/R (April 7, 2016)
checking
parser + scanner generated
0 errors detected