Recent

Author Topic: Parsing  (Read 970 times)

Borneq

  • Full Member
  • ***
  • Posts: 248
Parsing
« on: December 14, 2019, 12:21:13 am »
Lazarus is parsing and analysing text.
Which classes in which units can analyse syntax and lex?

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Parsing
« Reply #1 on: December 14, 2019, 02:00:32 am »
You could always make your own...

There a few simple things that need to be considered for a language parser I guess..

GET, GOT and EVAL  functions to start with..

GET is to read text letter by letter skipping over dead space accept where there is a case of being within a quoted set.

The GOT function will simply return the current CHAR while the GET function returns the next one etc.

 Normally what I do is if there is a token separator upon entry of the GET Function I'll keep looping until I hit the next valid character then return that one, otherwise return nothing #0..

 The GOT function is handy because It does not auto advance to the next character but simply returns the current one..

 Then you have the EVAL... Evaluation function, this will take the token resolved and determine its state in the mix. For example it could be a function or it could simply be constant value. The resolved value will get placed somewhere on the stack where by the next read you need to get the operator, that could be +-/* etc.

 and the list goes on

Of course there are always function parameters (..) to process and etc etc..

Are you up to it ?

The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Parsing
« Reply #2 on: December 14, 2019, 02:31:46 am »
In Lazarus there are
- Codetools
- SynEdit Highlighters (just parsing the structure of begin end and other keywords)
- For FpDebug's watch eval, there is a class in FpDebug. Basic expressions +/- and/or.

Fpc also includes a parser class somewhere that can be used (search the forum/mail list). IIRC fp-doc uses it.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Parsing
« Reply #3 on: December 14, 2019, 09:07:42 am »
Fpc also includes a parser class somewhere that can be used (search the forum/mail list). IIRC fp-doc uses it.
Actually more than one.
- The compiler sources itself (the reference)
- fcl-passrc  (used in e.g. pas2js)
Specialize a type, not a var.

 

TinyPortal © 2005-2018