LARA

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cc19:scallion [2019/10/09 12:20]
georg.schmid Typos
cc19:scallion [2019/10/09 12:24]
georg.schmid Typos
Line 26: Line 26:
 ==== Setup ==== ==== Setup ====
  
-In Scallion, parsers are called ​defined within a trait called ''​%%Syntaxes%%''​. This trait takes as parameters two types:+In Scallion, parsers are defined within a trait called ''​%%Syntaxes%%''​. This trait takes as parameters two types:
  
   * The type of tokens,   * The type of tokens,
Line 47: Line 47:
 ==== Writing Parsers ==== ==== Writing Parsers ====
  
-When writing a parser using parser combinators,​ one defines many smaller parsers and combine ​them together into more and more complex parsers. The top-level, most complex, of those parser then defines the entire syntax for the language. In our case, that top-level parser will be called ''​%%program%%''​.+When writing a parser using parser combinators,​ one defines many smaller parsers and combines ​them together into more and more complex parsers. The top-level, most complex, of those parser then defines the entire syntax for the language. In our case, that top-level parser will be called ''​%%program%%''​.
  
 All those parsers are objects of the type ''​%%Syntax[A]%%''​. The type parameter ''​%%A%%''​ indicates the type of values produced by the parser. For instance, a parser of type ''​%%Syntax[Int]%%''​ produces ''​%%Int%%''​s and a parser of type ''​%%Syntax[Expr]%%''​ produces ''​%%Expr%%''​s. Our top-level parser has the following signature: All those parsers are objects of the type ''​%%Syntax[A]%%''​. The type parameter ''​%%A%%''​ indicates the type of values produced by the parser. For instance, a parser of type ''​%%Syntax[Int]%%''​ produces ''​%%Int%%''​s and a parser of type ''​%%Syntax[Expr]%%''​ produces ''​%%Expr%%''​s. Our top-level parser has the following signature:
Line 54: Line 54:
 lazy val program: Parser[Program] = ... lazy val program: Parser[Program] = ...
 </​code>​ </​code>​
-Contrarily ​to the types of tokens and token kinds, which are fixed, the type of value produced is a type parameter of the various ''​%%Syntax%%''​s. This allows your different parsers to produce different ​type of values.+Contrary ​to the types of tokens and token kinds, which are fixed, the type of values ​produced is a type parameter of the various ''​%%Syntax%%''​s. This allows your different parsers to produce different ​types of values.
  
 The various parsers are stored as ''​%%val%%''​ members of the ''​%%Parser%%''​ object. In the case of mutually dependent parsers, we use ''​%%lazy val%%''​ instead. The various parsers are stored as ''​%%val%%''​ members of the ''​%%Parser%%''​ object. In the case of mutually dependent parsers, we use ''​%%lazy val%%''​ instead.