Pegjs : I want to write an expression so the input can work without errors =============================================

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Pegjs : I want to write an expression so the input can work without errors =============================================

Post by answerhappygod »

Pegjs : I want to write an expression so the input can
work without errors
===================================================================
input : 1 2 20 32.1 25E-9 10.23E+10
My current expression :
token = n:number ws? dot? dash? plus?{return
{"type":"T_NUMBER", "value":n};} / l:letter ws? dot? dash?
plus?{return {"type":"T_NUMBER", "value":l};}
digit "digit"= [0-9]
number "number" = digit+ {return text()}
ws "whitespace" = [\t \n \r]+
dot "dot" = [.]
dash "dash" = [-]
plus "plus" = [+]
letter "letter" = [a-zA-z]+ {return text()}
word = letter+ {return text()}
============================
But it has some errors:
Pegjs I Want To Write An Expression So The Input Can Work Without Errors 1
Pegjs I Want To Write An Expression So The Input Can Work Without Errors 1 (33.15 KiB) Viewed 42 times
FATI ./numbers.test.js • can scan and generate correct tokens for numbers expect(received).toBe(expected) // object.is equality - Expected + Received 6 + 30 @@ -11,16 +11,40 @@ "type": "T_NUMBER", "value": "20" "type": "T_NUMBER", "value" : "32.1" "value": "32" "type": "T_NUMBER", "value":"" "type": "T_NUMBER", "value": "25E-9" "type": "T_NUMBER", "value": "10.23E+10" "value": "25" "type": "T_NUMBER", "value": "Z" "type": "T_NUMBER", "value": "9" "type": "T_NUMBER", "value": "10" "type": "T_NUMBER", "value": "23" "type": "T_NUMBER", "value": "E" "type": "T_NUMBER", "value": "10" ]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply